/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Santiago.Escobar.M
 */
@Entity
@Table(name = "ruta")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Ruta.findAll", query = "SELECT r FROM Ruta r"),
    @NamedQuery(name = "Ruta.findByIdruta", query = "SELECT r FROM Ruta r WHERE r.idruta = :idruta"),
    @NamedQuery(name = "Ruta.findByOrigen", query = "SELECT r FROM Ruta r WHERE r.origen = :origen"),
    @NamedQuery(name = "Ruta.findByDestino", query = "SELECT r FROM Ruta r WHERE r.destino = :destino"),
    @NamedQuery(name = "Ruta.findByDistanciaaprox", query = "SELECT r FROM Ruta r WHERE r.distanciaaprox = :distanciaaprox")})
public class Ruta implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "idruta")
    private Long idruta;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "origen")
    private String origen;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "destino")
    private String destino;
    @Basic(optional = false)
    @NotNull
    @Column(name = "distanciaaprox")
    private int distanciaaprox;
    @JoinColumns({
        @JoinColumn(name = "isopais", referencedColumnName = "isopais"),
        @JoinColumn(name = "isociudad", referencedColumnName = "isociudad")})
    @ManyToOne(optional = false)
    private Ciudad ciudad;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idruta")
    private Collection<Rutavehiculo> rutavehiculoCollection;

    public Ruta() {
    }

    public Ruta(Long idruta) {
        this.idruta = idruta;
    }

    public Ruta(Long idruta, String origen, String destino, int distanciaaprox) {
        this.idruta = idruta;
        this.origen = origen;
        this.destino = destino;
        this.distanciaaprox = distanciaaprox;
    }

    public Long getIdruta() {
        return idruta;
    }

    public void setIdruta(Long idruta) {
        this.idruta = idruta;
    }

    public String getOrigen() {
        return origen;
    }

    public void setOrigen(String origen) {
        this.origen = origen;
    }

    public String getDestino() {
        return destino;
    }

    public void setDestino(String destino) {
        this.destino = destino;
    }

    public int getDistanciaaprox() {
        return distanciaaprox;
    }

    public void setDistanciaaprox(int distanciaaprox) {
        this.distanciaaprox = distanciaaprox;
    }

    public Ciudad getCiudad() {
        return ciudad;
    }

    public void setCiudad(Ciudad ciudad) {
        this.ciudad = ciudad;
    }

    @XmlTransient
    public Collection<Rutavehiculo> getRutavehiculoCollection() {
        return rutavehiculoCollection;
    }

    public void setRutavehiculoCollection(Collection<Rutavehiculo> rutavehiculoCollection) {
        this.rutavehiculoCollection = rutavehiculoCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idruta != null ? idruta.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Ruta)) {
            return false;
        }
        Ruta other = (Ruta) object;
        if ((this.idruta == null && other.idruta != null) || (this.idruta != null && !this.idruta.equals(other.idruta))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "modelo.Ruta[ idruta=" + idruta + " ]";
    }
    
}
